<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * 分类和标签设置
 * 
 */

class Catset extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('fuc');
        $this->load->library('topclass');
        $this->load->database();
        $this->config->load('topapiconfig');
        $this->load->model('cats_labs');
    }

    public function index() {
        echo "asdasd";
    }

    public function cat_list() {
        $data["cats_list_array"] = $cats = $this->cats_labs->get_cats();
        //print_r($rr);
        $this->load->view('admin/cats_list', $data);
    }

    public function cat_detail() {
        echo $id = get_segment_fuc(4);
        echo $sql = "select * from cats where id=\"{$id}\"";
        $query = $this->db->query($sql);
        $data["cat_detail_array"] = $query->result_array();
        $sql = "select * from catslab where catid=\"{$id}\"";
        $query = $this->db->query($sql);
        $data["cat_labs_array"] = $query->result_array();
        $this->load->view('admin/cats_detail', $data);
    }

    public function cat_delete() {
        echo $id = get_segment_fuc(4);
        echo $delsql = "delete from cats where id=\"{$id}\"";
        $this->db->query($delsql);
        redirect("admin/catset/cat_list");
        //   echo $delcallabsql="delete from cats where id=\"{$id}\"";
    }

    public function cat_add() {
        $insertsql = "insert into cats(name) values(\"{$_POST["catname"]}\") ";
        $this->db->query($insertsql);
        redirect("admin/catset/cat_list");
    }

    public function add_lab() {
        print_r($_POST);
        echo $insertsql = "insert into catslab(catid,labname) values(\"{$_POST["catid"]}\",\"{$_POST["labname"]}\") ";
        $this->db->query($insertsql);
        redirect("admin/catset/cat_list");
        exit;
    }

    public function del_lab() {        
        echo $id = get_segment_fuc(4);            
        echo $delsql = "delete from catslab where id=\"{$id}\"";
        $this->db->query($delsql);
        redirect("admin/catset/cat_list"); 
        
    }

}

?>
